<template>
  <div class="my-goods-item">
    <div class="left">
      <div class="custom-control custom-checkbox">
        <!-- 每个对象和组件都是独立的 -->
        <input type="checkbox" class="custom-control-input" :id="good.id" v-model='good.goods_state'>
        //循环所有的label的for都是input，id也是input，所以会导致只有第一个生效，所以用对象里面的id值关联
        <label class="custom-control-label" :for="good.id"> //:for将input和label关联起来 good.id值是固定的
          <img :src="good.goods_img" alt="">
        </label>
      </div>
    </div>
    <div class="right">
      <div class="top">{{ good.goods_name }}</div>
      <div class="bottom">
        <span class="price">{{ good.goods_price }}</span>
        <span>
            <MyCount :good='good' />
        </span>
      </div>
    </div>
  </div>
</template>

<script>
//引入数量的组件
import MyCount from "./MyCount"
export default {
  //接收父变量
  props: {
  good: Object//必须是对象
  },
  components: {
    //注册数量组件
    MyCount
  }
}
</script>

<style lang="less" scoped>
  .my-goods-item {
  display: flex;
  padding: 10px;
  border-bottom: 1px solid #ccc;
  .left {
    img {
      width: 120px;
      height: 120px;
      margin-right: 8px;
      border-radius: 10px;
    }
    .custom-control-label::before,
    .custom-control-label::after {
      top: 50px;
    }
  }
  .right {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .top{
        font-size: 14px;
        font-weight: 700;
    }
    .bottom {
      display: flex;
      justify-content: space-between;
      padding: 5px 0;
      align-items: center;
      .price {
        color: red;
        font-weight: bold;
      }
    }
  }
}

</style>